#include <config.h>
#include <debug.h>
#include <header.h>
#include <rules.h>
#include <xml_util.h>

#include "gui.h"
#include "language.h"
static void func_for_response(GtkDialog *dialog, gint response_id, gpointer user_data);
void show_icmp_dialog(void)
{
  GtkWidget *dialog = NULL;
  GtkWidget *frame_ping = NULL;
  GtkWidget *frame_request = NULL;
  GtkWidget *frame_reply = NULL;
  GtkWidget *frame_desc = NULL;
  GtkWidget *vbox_ping = NULL;
  GtkWidget *vbox_request = NULL;
  GtkWidget *vbox_reply = NULL;

  GtkWidget *checkbutton_allow_pinging = NULL;
  GtkWidget *checkbutton_allow_pinged = NULL;

  GtkWidget *checkbutton_request_timestap = NULL;
  GtkWidget *checkbutton_request_mask = NULL;
  GtkWidget *checkbutton_request_route = NULL;

  GtkWidget *checkbutton_reply_dest_unreachable = NULL;
  GtkWidget *checkbutton_reply_source_quench = NULL;
  GtkWidget *checkbutton_reply_param_problem = NULL;
  GtkWidget *checkbutton_reply_time_exceed = NULL;
  GtkWidget *checkbutton_reply_redirect = NULL;

  GtkWidget *desc_label = NULL;

  dialog = gtk_dialog_new_with_buttons(TEXT_ICMP_SETTING, NULL, 0,
                                       GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
                                       NULL);

  frame_ping = gtk_frame_new(TEXT_FRAME_PING);
  frame_request = gtk_frame_new(TEXT_FRAME_REQUEST);
  frame_reply = gtk_frame_new(TEXT_FRAME_REPLY);
  frame_desc = gtk_frame_new(TEXT_FRAME_DESC);

  gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), frame_ping, FALSE, FALSE, 5);
  gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), frame_request, FALSE, FALSE, 5);
  gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), frame_reply, FALSE, FALSE, 5);
  gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), frame_desc, FALSE, FALSE, 5);

  vbox_ping = gtk_vbox_new(TRUE, 5);
  gtk_container_add(GTK_CONTAINER(frame_ping), vbox_ping);

  vbox_request = gtk_vbox_new(TRUE, 5);
  gtk_container_add(GTK_CONTAINER(frame_request), vbox_request);

  vbox_reply = gtk_vbox_new(TRUE, 5);
  gtk_container_add(GTK_CONTAINER(frame_reply), vbox_reply);

  /*checkbutton of ping frame*/
  checkbutton_allow_pinging = gtk_check_button_new_with_label(TEXT_ALLOW_PINGING);
  checkbutton_allow_pinged = gtk_check_button_new_with_label(TEXT_ALLOW_PINGED);
  gtk_box_pack_start(GTK_BOX(vbox_ping), checkbutton_allow_pinging, FALSE, FALSE, 0);
  gtk_box_pack_start(GTK_BOX(vbox_ping), checkbutton_allow_pinged, FALSE, FALSE, 0);
  /*checkbutton of request frame*/
  checkbutton_request_timestap = gtk_check_button_new_with_label(TEXT_TIMESTAP_REQUEST);
  checkbutton_request_mask = gtk_check_button_new_with_label(TEXT_MASK_REQUEST);
  checkbutton_request_route = gtk_check_button_new_with_label(TEXT_ROUTE_REQUSET);
  gtk_box_pack_start(GTK_BOX(vbox_request), checkbutton_request_timestap, FALSE, FALSE, 0);
  gtk_box_pack_start(GTK_BOX(vbox_request), checkbutton_request_mask, FALSE, FALSE, 0);
  gtk_box_pack_start(GTK_BOX(vbox_request), checkbutton_request_route, FALSE, FALSE, 0);
  /*checkbutton of reply frame*/
  checkbutton_reply_dest_unreachable = gtk_check_button_new_with_label(TEXT_DEST_UNREACHABLE_REPLY);
  checkbutton_reply_source_quench = gtk_check_button_new_with_label(TEXT_SOURCE_QUENCH_REPLY);
  checkbutton_reply_param_problem = gtk_check_button_new_with_label(TEXT_PARAM_PROBLEM_REPLY);
  checkbutton_reply_time_exceed = gtk_check_button_new_with_label(TEXT_TIME_EXCEED_REPLY);
  checkbutton_reply_redirect = gtk_check_button_new_with_label(TEXT_REDIRECT_REPLY);
  gtk_box_pack_start(GTK_BOX(vbox_reply), checkbutton_reply_dest_unreachable, FALSE, FALSE, 0);
  gtk_box_pack_start(GTK_BOX(vbox_reply), checkbutton_reply_source_quench, FALSE, FALSE, 0);
  gtk_box_pack_start(GTK_BOX(vbox_reply), checkbutton_reply_param_problem, FALSE, FALSE, 0);
  gtk_box_pack_start(GTK_BOX(vbox_reply), checkbutton_reply_time_exceed, FALSE, FALSE, 0);
  gtk_box_pack_start(GTK_BOX(vbox_reply), checkbutton_reply_redirect, FALSE, FALSE, 0);

  /*conetent of desc frame*/
  desc_label = gtk_label_new(NULL);
  gtk_label_set_width_chars(GTK_LABEL(desc_label), 50);
  gtk_label_set_line_wrap(GTK_LABEL(desc_label), TRUE);
  gtk_label_set_text(GTK_LABEL(desc_label), TEXT_DESC_ICMP);
  gtk_container_add(GTK_CONTAINER(frame_desc), desc_label);
  /*connect signal*/
  gtk_signal_connect(GTK_OBJECT(dialog), "response",
                     G_CALLBACK(func_for_response), NULL);
  /*misc*/
  gtk_window_set_icon_from_file(GTK_WINDOW(dialog), COOLNET_TRAY_ICON, NULL);
  gtk_widget_show_all(dialog);
}

static void func_for_response(GtkDialog *dialog, gint response_id, gpointer user_data)
{
  if (GTK_RESPONSE_CLOSE == response_id)
  {
    gtk_widget_destroy(GTK_WIDGET(dialog));
  }
}
